package com.excesys.exsecs.om.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.om.entity.OmWPhone;
import com.excesys.exsecs.om.service.OmWPhoneSetupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 电话设置
 *
 * @author zh
 * @date 2023-04-23
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/phonesetup")
@Tag(name = "电话设置")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OmWPhoneSetupController {

	private final OmWPhoneSetupService omWPhoneSetupService;

	/**
	 * 电话设置查询
	 * @param omWPhone 电话设置
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('om_omphonesetup_get')")
	public R getPhonePage(Page page, OmWPhone omWPhone) {
		return R.ok(omWPhoneSetupService.page(page, Wrappers.query(omWPhone)));
	}

	/**
	 * 通过id查询电话设置表
	 * @param id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('om_omphonesetup_get')")
	public R getById(@PathVariable("id") Integer id) {
		return R.ok(omWPhoneSetupService.getById(id));
	}

	/**
	 * 电话设置新增
	 * @param omWPhone
	 * @return
	 */
	@Operation(summary = "新增电话设置表", description = "新增电话设置表")
	@SysLog("新增电话设置表")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('om_omphonesetup_add')")
	public R save(@RequestBody OmWPhone omWPhone) {
		return R.ok(omWPhoneSetupService.save(omWPhone));
	}

	/**
	 * 通过id删除电话设置表
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id删除电话设置表", description = "通过id删除电话设置表")
	@SysLog("通过id删除电话设置表")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('om_omphonesetup_del')")
	public R removeById(@PathVariable Integer id) {
		return R.ok(omWPhoneSetupService.removeById(id));
	}

	/**
	 * 修改电话设置表
	 * @param omWPhone 电话设置表
	 * @return R
	 */
	@Operation(summary = "修改电话设置表", description = "修改电话设置表")
	@SysLog("修改电话设置表")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('om_omphonesetup_edit')")
	public R updateById(@RequestBody OmWPhone omWPhone) {
		return R.ok(omWPhoneSetupService.updateById(omWPhone));
	}

}
